﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class GetLawyerScoreDetail : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LawyerScoreDetailOutParam result = new LawyerScoreDetailOutParam();
            LawyerScoreDetailInParam param = new LawyerScoreDetailInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as LawyerScoreDetailInParam;


                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                if (string.IsNullOrEmpty(param.LawyerID))
                {
                    result.code = "0";
                    result.desc = "律师ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    DataSet dsAllScore = LawCs.LawyerAllScore(param.LawyerID);
                    DataSet ds = LawCs.LawyerScore(param.LawyerID, param.page_no, param.page_count, "MobileService");
                    if (dsAllScore != null && dsAllScore.Tables[0].Rows.Count > 0)
                    {
                        if (string.IsNullOrEmpty(dsAllScore.Tables[0].Rows[0]["AllScore"].ToString()))
                        { result.AllScore = "0"; }
                        else
                        {
                            result.AllScore = dsAllScore.Tables[0].Rows[0]["AllScore"].ToString();
                        }
                    }
                    else
                    {
                        result.AllScore = "0";
                    }
                    if (ds != null && ds.Tables.Count == 2 && ds.Tables[0].Rows.Count > 0)
                    {
                        LawyerScoreData itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        result.LawyerName = ds.Tables[0].Rows[0]["UserName"].ToString();
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new LawyerScoreData();
                            itemTemp.ScoreID = dr["ScoreID"].ToString();
                            itemTemp.ScoreType = dr["ScoreType"].ToString();
                            itemTemp.Score = dr["Score"].ToString();
                            itemTemp.CreateTime = dr["CreateTime"].ToString();

                            result.data.list.Add(itemTemp);
                        }
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetLawyerScoreDetail", SerializeHelper.JsonSerializer<LawyerScoreDetailInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LawyerScoreDetailInParam, LawyerScoreDetailOutParam>();
            else
                SafeProcessRequest<LawyerScoreDetailInParam, LawyerScoreDetailOutParam>();
        }
    }

    #region 请求参数
    public class LawyerScoreDetailInParam
    {
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }

        /// <summary>
        /// 律师ID
        /// </summary>
        public string LawyerID
        { get; set; }

    }
    #endregion


    #region 结果参数
    public class LawyerScoreDetailOutParam
    {
        public LawyerScoreDetailOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LawyerScoreList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        /// <summary>
        /// 律师名称
        /// </summary>
        public string LawyerName
        { get; set; }

        /// <summary>
        /// 总积分
        /// </summary>
        public string AllScore
        { get; set; }

        public LawyerScoreList data
        { get; set; }

    }

    public class LawyerScoreList
    {
        public LawyerScoreList()
        {
            total_pages = 0;
            list = new List<LawyerScoreData>();
        }

        public List<LawyerScoreData> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }

    }

    public class LawyerScoreData
    {
        /// <summary>
        /// ID
        /// </summary>
        public string ScoreID
        { get; set; }

        /// <summary>
        /// 积分类型
        /// </summary>
        public string ScoreType
        { get; set; }

        /// <summary>
        /// 积分
        /// </summary>
        public string Score
        { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime
        { get; set; }
    }
    #endregion
}